package com.chrono.stock.populate;

import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;
import org.hibernate.cfg.Configuration;

import com.chrono.stock.dao.DataServiceFactory;
import com.chrono.stock.models.Client;
import com.chrono.stock.models.Telephone;

public class Populate {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(Populate.class);

	public static void main(String[] args) {
		if (logger.isDebugEnabled()) {
			logger.debug("main(String[]) - start");
		}

		// dropBase();
		launch();

		if (logger.isDebugEnabled()) {
			logger.debug("main(String[]) - end");
		}
	}

	public static void launch() {
		if (logger.isDebugEnabled()) {
			logger.debug("launch() - start");
		}

		Set<Telephone> phoneNumbers = new HashSet<Telephone>();
		phoneNumbers.add(new Telephone("32354353"));
		phoneNumbers.add(new Telephone("9889343423"));

		Client student = new Client();
		student.setTels(phoneNumbers);
		DataServiceFactory.getInstance().persist(student);

		if (logger.isDebugEnabled()) {
			logger.debug("launch() - end");
		}
	}

	public static void dropBase() {
		if (logger.isDebugEnabled()) {
			logger.debug("dropBase() - start");
		}

		Configuration cfg = new Configuration().configure();
		cfg.setProperty("hibernate.hbm2ddl.auto", "create");
		cfg.buildSessionFactory();

		if (logger.isDebugEnabled()) {
			logger.debug("dropBase() - end");
		}
	}
}
